Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for view_my_profile.
	''' </summary>
	Public Partial Class welcome
		Inherits BaseWebPage
		Protected litFriendsCount As System.Web.UI.WebControls.Literal
		Public blankImagesCount As Integer = 0
		Protected lblPhotosCount As System.Web.UI.WebControls.Label
		Protected sFriendsCount As String = ""
		Protected Hyperlink1 As System.Web.UI.WebControls.HyperLink
		Protected hlUploadSongs As System.Web.UI.WebControls.HyperLink
		Protected lblMyInbox As System.Web.UI.WebControls.Label
		Protected lblMyFriendsComments As System.Web.UI.WebControls.Label
		Protected lblBulletinBoard As System.Web.UI.WebControls.Label
		Protected lblGroupBulletinBoard As System.Web.UI.WebControls.Label
		Protected lblBlog As System.Web.UI.WebControls.Label
		Protected htPageConstants As New Hashtable()


		Public Function CreateDataSource(ByVal type As String) As ICollection
			Dim usr As BO.User = LoggedUser

			Dim startIndex As Integer = 0
			Dim endIndex As Integer = startIndex + Constants.MAX_PICTURES_ON_WELCOME_PAGE
			If type = "nf" Then
				endIndex -= 4
			End If
			' four new users less than the direct friends
			Dim i As Integer
			Dim dt As New DataTable()
			Dim dr As DataRow

			dt.Columns.Add(New DataColumn("ImageURL", GetType(String)))
			dt.Columns.Add(New DataColumn("Name", GetType(String)))
			dt.Columns.Add(New DataColumn("OnlineImg", GetType(String)))
			dt.Columns.Add(New DataColumn("FriendID", GetType(String)))
			dt.Columns.Add(New DataColumn("FriendItemURL", GetType(String)))
			dt.Columns.Add(New DataColumn("FullName", GetType(String)))

			Dim temp As UserPicture
			Dim tmpUserPic As UserPicture = Nothing

			blankImagesCount = 0
			Dim imagesOnLastRow As Integer = 0
			Dim t As Integer = 0
			Dim counter As Integer = 0
			Dim FriendsCount As Integer
			Dim LoggedUsersList As ArrayList = Common.Utils.GetLoggedUsersIDs()

			Select Case type
				Case "df"
					Dim ufList As UsersFriends = usr.DirectFriends
					Dim usrDFWithMazFirst As New ArrayList()
					FriendsCount = ufList.Count

					endIndex = Math.Min(endIndex, FriendsCount)
					t = (endIndex - startIndex)
					Math.DivRem(t, Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE, imagesOnLastRow)

					' maz's user to be the first
					Dim usrMaz As User = Users.GetUserByEmail(Constants.WELCOME_MESSAGE_SENDER)
					'						bool bMaz = false;
					'						if( ufList.Contains(usrMaz.ID) )
					'						{
					'							dr = dt.NewRow();
					'
					'							tmpUserPic = usrMaz.DefaultPicture;
					'							if(tmpUserPic != null)
					'							{
					'								dr[0] = Pictures.GetPictureSrcFullURL( tmpUserPic, true, "../");
					'							}
					'							else
					'							{
					'								dr[0] = "../images/default_thumbnail.gif";
					'							}
					'							dr[1] = getBeginning(usrMaz.Name, Constants.MAX_NAME_LENGTH_ABOVE_IMAGE);
					'							if(LoggedUsersList.Contains(usrMaz.ID))
					'								dr[2] = "../images/online_status.gif";
					'							else
					'								dr[2] = "../images/spacer.gif"; 
					'							dr[3] = usrMaz.ID;
					'							dr[4] = "../" + Constants.MEMBERS + "?id=" + usrMaz.ID;
					'
					'							dt.Rows.Add(dr);
					'							
					'							if( t == Constants.MAX_PICTURES_ON_WELCOME_PAGE )
					'							{
					'								bMaz = true;
					'								t--;
					'							}
					'						}

					Dim mazFound As Boolean = False
					For Each udf As DirectFriend In ufList
						If udf.[Friend].ID = usrMaz.ID Then
							usrDFWithMazFirst.Insert(0, udf)
							mazFound = True
						Else
							usrDFWithMazFirst.Add(udf)
						End If
					Next

					If mazFound Then
						If usrDFWithMazFirst.Count > 2 Then
							usrDFWithMazFirst.Sort(1, usrDFWithMazFirst.Count - 1, New BO.GenericSort("DateAdded", "DESC"))
						End If
					Else
						usrDFWithMazFirst.Sort(New BO.GenericSort("DateAdded", "DESC"))
					End If

					Dim idx As Integer = 0
					While idx < t
						'						DirectFriend df = (DirectFriend) ufList.GetList()[ idx ];

						' maz's user to be the first
						'if(df.Friend.ID == usrMaz.ID)
						'{
						'	if( ( t < Constants.MAX_PICTURES_ON_WELCOME_PAGE ) && bMaz )
						'		t++;
						'	continue;
						'}

						Dim df As DirectFriend = DirectCast(usrDFWithMazFirst(idx), DirectFriend)

						dr = dt.NewRow()

						tmpUserPic = df.[Friend].DefaultPicture
						If tmpUserPic <> Nothing Then
							dr(0) = Pictures.GetPictureSrcFullURL(tmpUserPic, True, "../")
						Else
							dr(0) = "../images/default_thumbnail.gif"
						End If
						dr(1) = getBeginning(HttpUtility.HtmlEncode(df.[Friend].Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
						If LoggedUsersList.Contains(df.[Friend].ID) Then
							dr(2) = "../images/online_status.gif"
						Else
							dr(2) = "../images/spacer.gif"
						End If
						dr(3) = df.[Friend].ID
						dr(4) = "../" + Constants.MEMBERS + "?id=" + df.[Friend].ID
						dr(5) = df.[Friend].Name
						dt.Rows.Add(dr)
						System.Math.Max(System.Threading.Interlocked.Increment(idx),idx - 1)
					End While
					Exit Select
				Case "nf"
					'								ArrayList usrNetworkedUsers = Users.FindNetworkedUsers(usr.ID, 4, false);
'
'											FriendsCount = usrNetworkedUsers.Count;
'
'											endIndex = Math.Min(endIndex, FriendsCount);
'											t = (endIndex - startIndex);
'											Math.DivRem(t , Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE, out imagesOnLastRow);
'											counter = 0;
'
'											foreach (BO.NetworkFriend nf in usrNetworkedUsers)  
'											{
'												if(counter >= startIndex && counter < endIndex)
'												{
'													dr = dt.NewRow();
'													temp = nf.Friend.DefaultPicture;
'													if(temp != null)
'													{
'														dr[0] = Pictures.GetPictureSrcFullURL( temp, true, "../");
'													}
'													else
'													{
'														dr[0] = "../images/default_thumbnail.gif";
'													}
'													dr[1] = getNameBeginning(nf.Friend.Name);
'													if(LoggedUsersList.Contains(nf.Friend.ID))
'														dr[2] = "../images/online_status.gif";
'													else
'														dr[2] = "../images/spacer.gif"; 
'													dr[3] = nf.Friend.ID;
'													dt.Rows.Add(dr);
'												}
'												counter++;
'											}
'
'					

					Dim usrNetworkedUsers As ArrayList = Users.GetRandomUsers(Constants.RANDOM_USERS_COUNT_ON_WELCOME_PAGE, False)

					FriendsCount = usrNetworkedUsers.Count

					endIndex = Math.Min(endIndex, FriendsCount)
					t = (endIndex - startIndex)
					Math.DivRem(t, Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE, imagesOnLastRow)
					counter = 0

					For Each nf As BO.User In usrNetworkedUsers
						If counter >= startIndex AndAlso counter < endIndex Then
							dr = dt.NewRow()
							temp = nf.DefaultPicture
							If temp <> Nothing Then
								dr(0) = Pictures.GetPictureSrcFullURL(temp, True, "../")
							Else
								dr(0) = "../images/default_thumbnail.gif"
							End If
							dr(1) = getBeginning(HttpUtility.HtmlEncode(nf.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
							If LoggedUsersList.Contains(nf.ID) Then
								dr(2) = "../images/online_status.gif"
							Else
								dr(2) = "../images/spacer.gif"
							End If
							dr(3) = nf.ID
							dr(4) = "../" + Constants.MEMBERS + "?id=" + nf.ID
							dr(5) = nf.Name
							dt.Rows.Add(dr)
						End If
						System.Math.Max(System.Threading.Interlocked.Increment(counter),counter - 1)
					Next
					Exit Select
			End Select

			If imagesOnLastRow <> 0 Then
				blankImagesCount = Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE - imagesOnLastRow
				i = imagesOnLastRow
				While i < Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE
					dr = dt.NewRow()
					'dr[0] = "../images/empty_image.gif";
					dr(0) = "../images/spacer.gif"
					dr(1) = ""
					dr(2) = "../images/spacer.gif"
					dt.Rows.Add(dr)
					System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
				End While
			End If

			Dim dv As New DataView(dt)
			Return dv
		End Function

		Public Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs)
			' this.pageTemplate.PageTitle = PageTitles.WELCOME_PAGE;
			Dim usr As User = LoggedUser

			If usr = Nothing Then
				Response.Redirect(Constants.[DEFAULT])
			End If

			Me.initPageTitles(Constants.WELCOME, "", Form1, Nothing, htPageConstants)
			Me.initAdvertisements(Form1, Nothing)

			If Constants.SHOW_GROUPS <> Constants.SHOW_ON Then
				hlMyGroups.Visible = False
				hlFavouriteGroups.Visible = False
				trGroupBulletin.Visible = False
				trGroupBulletinBoard.Visible = False
				litNewLine.Visible = False
				litSpacer.Visible = False
				divFavGroups.Visible = False
			Else
				hlMyGroups.Visible = True
				hlFavouriteGroups.Visible = True
				trGroupBulletin.Visible = True
				trGroupBulletinBoard.Visible = True
				litNewLine.Visible = True
				litSpacer.Visible = True
			End If

			litName.Text = LoggedUser.Name
			litTimesViewed.Text = " " + usr.TimesViewed
			Dim userPicture As UserPicture = usr.DefaultPicture
			hlMoreTips.NavigateUrl = "../#t"
			hlMoreTips.Attributes.Add("onclick", "javascript: loadRandomTip('_ctl0_lblTip');")
			' set user's image
			If userPicture <> Nothing Then
				imgUserPicture.ImageUrl = Pictures.GetPictureLargeThumbnailSrcFullURL(userPicture, "../")
			Else
				imgUserPicture.ImageUrl = "../images/default_thumbnail.gif"
			End If
			imgUserPicture.ToolTip = usr.Name

			' set friends count
			Dim ufList As UsersFriends = usr.DirectFriends
			sFriendsCount = ufList.Count.ToString()

			' set Photos count
			Dim pics As ArrayList = usr.GetPictures()
			hlPhotosLink.Text = "<font class='main_text_opposite_bold'>" + pics.Count.ToString() + "</font>" + " Photo"
			If pics.Count <> 1 Then
				hlPhotosLink.Text += "s"
			End If
			hlPhotosLink.Text += " in Album"

			hlPhotosLink.NavigateUrl = "../" + Constants.UPLOAD_PHOTO

			' set notes table

			'if(usr.DefaultPicture == null || usr.Status == Constants.UNCONFIRMED_STATUS)
			If usr.DefaultPicture = Nothing Then
				Dim lblNotes As New Label()
				lblNotes.Text = Me.GetPageConstText(htPageConstants, "CONST_Notes_TEXT")
				Dim controls As New ArrayList()
				controls.Add(lblNotes)
				addTableRow("notes", controls)
			End If

			' commented on 12.09.2004
			'					if(usr.Status == Constants.UNCONFIRMED_STATUS)
'							{
'								ArrayList controls_unreg = new ArrayList();
'
'								Label lblNote_unregistered = new Label();
'								TimeSpan confPeriod = DateTime.Today - usr.RegistrationDate;
'
'								//lblNote_unregistered.Text = "&nbsp;&nbsp;You have " + (Constants.REGISTRATION_PERIOD - confPeriod.Days) + " days to confirm your account.";
'								lblNote_unregistered.Text = "&nbsp;&nbsp;Please <a href='" + Constants.WELCOME_MSG + "'>Verify</a> your Email Address.";
'								controls_unreg.Add(lblNote_unregistered);
'
'								addTableRow("notes_td", controls_unreg);
'							}								
'			

			'end set notes table
			If usr.DefaultPicture = Nothing Then
				Dim controls As New ArrayList()

				Dim lblNote As New Label()
				lblNote.Text = Me.GetPageConstText(htPageConstants, "CONST_Upload_TEXT")
				controls.Add(lblNote)

				addTableRow("notes_td", controls)
			End If

			' set new messages count link
			Dim list As ArrayList = Messages.GetUserInboxUnreadMessages(usr.ID, False)

			Dim cnt As Integer = list.Count
			If cnt = 0 Then
				lblNewMessages.Visible = False
			Else
				lblNewMessages.Text = cnt + " New Message"
				If cnt > 1 Then
					lblNewMessages.Text += "s"
				End If
			End If

			'set new comments count link

			list = usr.NewComments
			cnt = list.Count
			If cnt = 0 Then
				lblNewComments.Visible = False
			Else
				lblNewComments.Text = cnt + " New Comment"
				If cnt > 1 Then
					lblNewComments.Text += "s"
				End If
			End If

			'set new bulletins count link

			Dim arrBulletinList As ArrayList = Messages.GetAllUserBulletins(usr.ID, False, False)
			cnt = arrBulletinList.Count
			If cnt = 0 Then
				lblNewBulletins.Visible = False
			Else
				lblNewBulletins.Text = cnt + " New Bulletin"
				If cnt > 1 Then
					lblNewBulletins.Text += "s"
				End If
			End If

			'set new group bulletins count link
			Dim arrGroupBulletinList As ArrayList = Messages.GetUserGroupBulletins(usr.ID, -1, -1)
			cnt = arrGroupBulletinList.Count
			If cnt = 0 Then
				lblNewGroupBulletins.Visible = False
			Else
				lblNewGroupBulletins.Text = cnt + " New Group Bulletin"
				If cnt > 1 Then
					lblNewGroupBulletins.Text += "s"
				End If
			End If

			' set Tips

			Dim randomNumber As New Random()
			lblTip.Text = Constants.TIPS_ARRAY(randomNumber.[Next](0, Constants.TIPS_ARRAY.Length - 1))

			' set direct friends visibility
			If ufList.Count = 0 Then
				tblFriends.Visible = False
				hlSeeAllFriendsUp.Visible = False
				hlSeeAllFriendsDown.Visible = False
				imgEditFriends.Visible = False
				lbEditFriends.Visible = False
				lblNoFriends.Visible = True
			End If

			Dim usrNetworkedUsers As ArrayList = Users.FindNetworkedUsers(usr.ID, 4, False)
			'hlViewMorePeople.NavigateUrl = "../" + Constants.SEE_ALL_NETWORK_FRIENDS;
			hlViewMorePeople.NavigateUrl = "../" + Constants.BROWSE

			'if(usrNetworkedUsers.Count == 0)
			'{		
			'	tblNewPeople.Visible = false;
			'	lblNoNewPeople.Visible = true;
			'	hlViewMorePeople.Visible = false;
			'}						

			lblNetworkPeopleCount.Text = usrNetworkedUsers.Count.ToString()
			lblDirectFriendsCount.Text = ufList.Count.ToString()

			Dim invUsers As UserInvitations = usr.PendingInvitations
			If invUsers.Count > 0 Then
				hlViewConfirmation.NavigateUrl = "../" + Constants.VIEW_AWAITING_CONFIRMATION
				hlViewConfirmation.Text = (GetPageConstText(htPageConstants, "CONST_ViewAwaiting_TEXT")).Replace("[PARAM]", invUsers.Count.ToString())
				hlViewConfirmation.Visible = True
			End If

			' Bind data
			If Not IsPostBack Then
				If ufList.Count <> 0 Then
					BindList("df")
				End If
				'if(usrNetworkedUsers.Count != 0)
				BindList("nf")
				'BindGrid(dgBulletins, "bulletin");
				BindGrid(dgBulletins, "inbox")
				BindGrid(dgGroupBulletins, "groupbulletin")
				BindGrid(dgBlog, "blog")
			End If
		End Sub

		Private Sub addTableRow(ByVal cssclass As String, ByVal ctls As ArrayList)
			Dim tr As New TableRow()
			Dim td As New TableCell()
			td.CssClass = cssclass
			For Each ctl As Control In ctls
				td.Controls.Add(ctl)
			Next
			tr.Cells.Add(td)
			tblNotes.Rows.Add(tr)
		End Sub

		Public Sub BindList(ByVal type As String)
			Dim itemsCount As Integer
			Dim blankImageIndex As Integer
			Dim i As Integer

			Select Case type
				Case "nf"
					dlNewPeople.DataSource = CreateDataSource(type)
					dlNewPeople.DataBind()

					itemsCount = dlNewPeople.Items.Count
					blankImageIndex = itemsCount - blankImagesCount
					i = 0
					i = blankImageIndex
					While i < itemsCount
						(DirectCast(dlNewPeople.Items(i).FindControl("hlName"), System.Web.UI.WebControls.HyperLink)).CssClass = "empty_image"
						(DirectCast(dlNewPeople.Items(i).FindControl("hlPhoto"), System.Web.UI.WebControls.HyperLink)).CssClass = "empty_image"
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					Exit Select
				Case "df"
					dlAllFriends.DataSource = CreateDataSource(type)
					dlAllFriends.DataBind()

					itemsCount = dlAllFriends.Items.Count
					blankImageIndex = itemsCount - blankImagesCount
					i = 0
					i = blankImageIndex
					While i < itemsCount
						(DirectCast(dlAllFriends.Items(i).FindControl("hlName"), System.Web.UI.WebControls.HyperLink)).CssClass = "empty_image"
						(DirectCast(dlAllFriends.Items(i).FindControl("hlPhoto"), System.Web.UI.WebControls.HyperLink)).CssClass = "empty_image"
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					Exit Select
			End Select
		End Sub

		Protected Function CreateDataSourceForGrid(ByVal type As String) As ICollection
			Dim usr As BO.User = LoggedUser

			Dim msgList As ArrayList
			Dim dt As New DataTable()

			' List user's inbox messages
			Select Case type
				Case "bulletin"
					' changed according to the All_Networking_190105.xls, ID 54,55
					'msgList = Messages.GetUserInboxBulletins( usr.ID, false );
					msgList = Messages.GetAllUserBulletins(usr.ID, False)
					Exit Select
				Case "groupbulletin"
					msgList = Messages.GetUserGroupBulletins(usr.ID, 0, -1)
					Exit Select
				Case "blog"
					msgList = Messages.GetUserBlogs(usr.ID)
					Exit Select
				Case Else
					' changed according to the All_Networking_190105.xls, ID 54,55
					'msgList = Messages.GetUserInboxBulletins( usr.ID, false );
					'msgList = Messages.GetAllUserBulletins( usr.ID, false );
					msgList = Messages.GetUserInboxMessagesGroupBulletins(usr.ID, False)
					Exit Select
			End Select
			If msgList.Count = 0 Then
				If type = "bulletin" Then
					dgBulletins.Visible = False
					hlAllBulletin.Visible = False
					lblEmptyBulletins.Visible = True
				End If
				If type = "groupbulletin" Then
					dgGroupBulletins.Visible = False
					hlAllGroupBulletins.Visible = False
					lblEmptyGroupBulletins.Visible = True
				End If
				If type = "blog" Then
					dgBlog.Visible = False
					hlAllBlog.Visible = False
					lblEmptyBlog.Visible = True
				End If
			Else
				Dim startIndex As Integer = 0
				Dim endIndex As Integer = startIndex + Constants.MAX_MESSAGES_ON_WELCOME_PAGE
				endIndex = Math.Min(endIndex, msgList.Count)
				Dim curMessageDate As DateTime
				Dim dr As DataRow

				dt.Columns.Add(New DataColumn("MessageID", GetType(Integer)))
				dt.Columns.Add(New DataColumn("Date", GetType(String)))
				dt.Columns.Add(New DataColumn("URL", GetType(String)))
				dt.Columns.Add(New DataColumn("FriendID", GetType(String)))
				dt.Columns.Add(New DataColumn("SenderName", GetType(String)))
				dt.Columns.Add(New DataColumn("Subject", GetType(String)))
				dt.Columns.Add(New DataColumn("ViewMsgURL", GetType(String)))
				dt.Columns.Add(New DataColumn("OnClickJS", GetType(String)))
				dt.Columns.Add(New DataColumn("TypeImageURL", GetType(String)))
				dt.Columns.Add(New DataColumn("TypeName", GetType(String)))
				'dt.Columns.Add(new DataColumn("MessageIDAndType", typeof(string)));

				' List user's inbox messages					
				Dim i As Integer = startIndex
				While i < endIndex
					dr = dt.NewRow()

					Select Case type
						Case "bulletin"
							Dim bul As BulletinMessage = DirectCast(msgList(i), BulletinMessage)
							curMessageDate = bul.DateSent
							dr(0) = bul.ID
							dr(1) = Constants.ARR_MONTHS(curMessageDate.Month - 1) + " " + curMessageDate.Day + "<br />" + curMessageDate.ToShortTimeString()

							dr(2) = Users.ComposeMemeberLink(bul.Sender)
							dr(7) = Users.ComposeMemeberLinkOnClickJS(bul.Sender, trUserCanceledMessage)

							dr(3) = bul.SenderID.ToString()
							dr(4) = getBeginning(HttpUtility.HtmlEncode(bul.Sender.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
							dr(5) = Server.HtmlEncode(bul.Subject)
							dr(6) = "../" + Constants.VIEW_MESSAGE + "?id=" + bul.ID + "&" + Constants.MSGBOX_PARAM + "=" + Constants.MSGBOX_BULLETIN
							Exit Select
						Case "groupbulletin"
							Dim grbul As GroupBulletinMessage = DirectCast(msgList(i), GroupBulletinMessage)
							curMessageDate = grbul.DateSent
							dr(0) = grbul.ID
							dr(1) = Constants.ARR_MONTHS(curMessageDate.Month - 1) + " " + curMessageDate.Day + "<br />" + curMessageDate.ToShortTimeString()

							dr(2) = Users.ComposeMemeberLink(grbul.Sender)
							dr(7) = Users.ComposeMemeberLinkOnClickJS(grbul.Sender, trUserCanceledMessage)

							dr(3) = grbul.SenderID.ToString()
							dr(4) = getBeginning(HttpUtility.HtmlEncode(grbul.Sender.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
							dr(5) = Server.HtmlEncode(grbul.Subject)
							dr(6) = "../" + Constants.VIEW_MESSAGE + "?id=" + grbul.ID + "&" + Constants.GROUP_PARAM + "=" + grbul.GroupID + "&" + Constants.USER_MODE_PARAM + "=true" + "&" + Constants.MSGBOX_PARAM + "=" + Constants.MSGBOX_GROUP_BULLETIN
							Exit Select
						Case "blog"
							Dim blog As Blog = DirectCast(msgList(i), Blog)
							curMessageDate = blog.DateSent
							dr(0) = blog.ID
							dr(1) = Constants.ARR_MONTHS(curMessageDate.Month - 1) + " " + curMessageDate.Day + "<br />" + curMessageDate.ToShortTimeString()
							dr(2) = Users.ComposeMemeberLink(blog.Sender)
							dr(3) = blog.SenderID.ToString()
							dr(4) = getBeginning(HttpUtility.HtmlEncode(blog.Sender.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
							dr(5) = Server.HtmlEncode(blog.Subject)
							dr(6) = "../" + Constants.VIEW_BLOG_COMMENTS + "?id=" + blog.ID
							dr(7) = Users.ComposeMemeberLinkOnClickJS(blog.Sender, trUserCanceledMessage)
							Exit Select
						Case Else
							Dim msg As Message = DirectCast(msgList(i), Message)
							curMessageDate = msg.DateSent
							dr(0) = msg.ID
							dr(1) = Constants.ARR_MONTHS(curMessageDate.Month - 1) + " " + curMessageDate.Day + "<br />" + curMessageDate.ToShortTimeString()
							dr(2) = Users.ComposeMemeberLink(msg.Sender)
							'"../" + Constants.MEMBERS + "?id=" + msg.SenderID.ToString();
							dr(3) = msg.SenderID.ToString()
							dr(4) = getBeginning(HttpUtility.HtmlEncode(msg.Sender.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
							dr(5) = Server.HtmlEncode(msg.Subject)
							dr(6) = "../" + Constants.VIEW_MESSAGE + "?id=" + msg.ID + "&" + Constants.MSG_TYPE_PARAM + "=" + DirectCast(msg.MessageType, Integer) + "&" + Constants.MSGBOX_PARAM + "=" + Constants.MSGBOX_INBOX
							dr(7) = Users.ComposeMemeberLinkOnClickJS(msg.Sender, trUserCanceledMessage)
							'"return;";
							Select Case msg.MessageType
								Case Messages.MessageType.mtBulletin
									dr(8) = Constants.BULLETIN_IMAGE_URL
									dr(9) = Constants.MSG_TYPE_NAME_BULLETIN
									Exit Select
								Case Messages.MessageType.mtGroupBulletin
									dr(8) = Constants.GROUP_BULLETIN_IMAGE_URL
									dr(9) = Constants.MSG_TYPE_NAME_GRP_BULLETIN
									Exit Select
								Case Else
									dr(8) = Constants.MESSAGE_IMAGE_URL
									dr(9) = Constants.MSG_TYPE_NAME_MESSAGE
									Exit Select
							End Select
							Exit Select
					End Select
					dt.Rows.Add(dr)
					System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
				End While
			End If
			Dim dv As New DataView(dt)
			Return dv
		End Function

		Protected Sub BindGrid(ByVal gridName As DataGrid, ByVal type As String)
			'init datagrid with database data ordered by "orederBy" param
			gridName.DataSource = CreateDataSourceForGrid(type)
			gridName.DataBind()
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			AddHandler Me.dgBulletins.ItemCommand, AddressOf Me.dgBulletins_ItemCommand
		End Sub
#End Region

		Protected Sub lbEditFriends_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			Response.Redirect(Constants.SEE_ALL_FRIENDS + "?action=" + Constants.SEE_ALL_FRIENDS_EDIT_ACTION)
		End Sub

		Private Sub dlAllFriends_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs)
			Dim src As Object = e.CommandSource
			Dim srcType As String = src.[GetType]().ToString()
			Dim cmd As String = e.CommandName
			Dim arg As String = ""
			If srcType.Equals("System.Web.UI.WebControls.ImageButton") Then
				arg = (DirectCast(src, ImageButton)).CommandArgument
			Else
				arg = (DirectCast(src, LinkButton)).CommandArgument
			End If
			Select Case cmd
				Case "MemberRedirect"
					Response.Redirect(Constants.MEMBERS + "?id=" + e.CommandArgument)
					Exit Select
			End Select
		End Sub

		Private Sub dgBulletins_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
			Dim src As Object = e.CommandSource
			Dim srcType As String = src.[GetType]().ToString()
			Dim cmd As String = e.CommandName
			Dim arg As String = ""
			If srcType.Equals("System.Web.UI.WebControls.ImageButton") Then
				arg = (DirectCast(src, ImageButton)).CommandArgument
			Else
				arg = (DirectCast(src, LinkButton)).CommandArgument
			End If
			Select Case cmd
				Case "MemberRedirect"
					Response.Redirect(Constants.MEMBERS + "?id=" + e.CommandArgument)
					Exit Select
			End Select
		End Sub

		Protected Sub lbAddFriends_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			Response.Redirect(Constants.INVITE_FRIENDS_PAGE)
		End Sub

		====================
		' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable Form1.
		====================
		Public ReadOnly Property Form1() As System.Web.UI.HtmlControls.HtmlForm
			Get
				Return Migrated_Form1
			End Get
		End Property
		'set { Migrated_Form1 = value; }
	End Class
End Namespace







